"""
    @Author  ：思念 
    @File    ：0.demo.py
    @Date    ：2025/3/21 14:55 
"""
import requests
import jsonpath
url = 'https://careers.tencent.com/tencentcareer/api/post/Query'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
}

def get_work_info(page):
    params = {
        'timestamp': 1696774900608,
        'countryId': '',
        'cityId': '',
        'bgIds': '',
        'productId': '',
        'categoryId': '',
        'parentCategoryId': '',
        'attrId': '',
        'keyword': 'python',
        'pageIndex': page,
        'pageSize': 10,
        'language': 'zh-cn',
        'area': 'cn'
    }
    response = requests.get(url, headers=headers, params=params).json()
    print(response)
    # 在某些页面中不存在当前的json数据会跑出异常
    # try:
    #     for info in response['Data']['Posts']:
    #         work_info_dict = dict()
    #         work_info_dict['recruit_post_name'] = jsonpath.jsonpath(info, '$..RecruitPostName')[0]
    #         work_info_dict['country_name'] = jsonpath.jsonpath(info, '$..CountryName')[0]
    #         work_info_dict['location_name'] = jsonpath.jsonpath(info, '$..LocationName')[0]
    #         work_info_dict['category_name'] = jsonpath.jsonpath(info, '$..CategoryName')[0]
    #         work_info_dict['responsibility'] = jsonpath.jsonpath(info, '$..Responsibility')[0]
    #         work_info_dict['last_update_time'] = jsonpath.jsonpath(info, '$..LastUpdateTime')[0]
    #         print(work_info_dict)
    #         # 存放到队列中，父进程会从队列中取数据
    #         # queue.put(work_info_dict)
    # except TypeError:
    #     print('数据不存在:', params.get('pageIndex'))

get_work_info(1)